/**刷新验证码**/
function reloadCode() {$("#validateCodeImg").attr("src", ctx + "image/code?data=" + new Date() + "");}
/**登陆**/
function formLogin() {
    var $loginButton = $("#form-login-button");
    var username = $("input[name='username']").val().trim();
    var password = $("input[name='password']").val().trim();
    var $form = $("#loginForm");
    if (username === "") {pnotify("error","请输入账号");return;}
    if (password === "") {pnotify("error","请输入密码");return;}
    $loginButton.html("").append("<div class='login-loder'><div class='line-scale'><div></div><div></div><div></div><div></div><div></div></div></div>");
    $.ajax({
        type: "post",
        url: ctx + "form/login",
        data: $form.serialize()+"&remember-me=on",
        dataType: "json",
        success: function (r) {
            if (r.code === 0) {
                $form[0].reset();
                location.href = ctx + 'index';
            } else {
                if (r.msg !== '验证码不能为空！') reloadCode();
                pnotify("error",r.msg);
                $loginButton.html("登录");
            }
        }
    });
}
/**提示信息全局配置**/
function pnotify(type,msg){
    if(type=="error"){
        new PNotify({title: '错误',text: msg,type: 'error',styling: 'bootstrap3'});
    }else{
        new PNotify({title: '成功',text: msg,type: 'success',styling: 'bootstrap3'});
    }
}
